//rem手机适配
new function () {
    var _self = this;
    _self.width = 640;//设置默认最大宽度
    _self.fontSize = 100;//默认字体大小
    _self.widthProportion = function () {
        var p = (document.body && document.body.clientWidth || document.getElementsByTagName("html")[0].offsetWidth) / _self.width;
        return p > 1 ? 1 : p < 0.5 ? 0.5 : p;
    };
    _self.changePage = function () {
        document.getElementsByTagName("html")[0].setAttribute("style", "font-size:" + _self.widthProportion() * _self.fontSize + "px !important");
    }
    _self.changePage();
    window.addEventListener('resize', function () {
        _self.changePage();
    }, false);
};


//地图
function init(market){
    var map = new AMap.Map('marketmap', {
        resizeEnable: true,
        center: [market.mLng, market.mLat],
        zoom: 12
    });
    map.plugin(["AMap.ToolBar"], function() {
        map.addControl(new AMap.ToolBar());
    });
    //
    var marker;
    marker = new AMap.Marker({
        icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
        position: [market.mLng, market.mLat],
        map:map
    });
    //marker.setMap(map);
    AMap.event.addListener(marker, 'click', function() {
    });
    //实例化信息窗体
    var title = market.mName+'<span style="font-size:11px;color:#F00;"></span>',
        content = [];
    content.push("<img style='width:85px;' src='"+market.mPic+"'><span style='white-space: nowrap;overflow: hidden;text-overflow: ellipsis;display: block;'>地址："+market.mAddr+"</span><span>电话："+market.mManagertel+"</span><span style='    white-space: nowrap;overflow: hidden;text-overflow: ellipsis;display: block;max-width: 230px;'>详细信息："+market.mIntroduction+"</span>");
    var infoWindow = new AMap.InfoWindow({
        isCustom: true,  //使用自定义窗体
        content: createInfoWindow(title, content.join("<br/>")),
        offset: new AMap.Pixel(16, -45)
    });
//鼠标点击marker弹出自定义的信息窗体
    AMap.event.addListener(marker, 'click', function() {
        infoWindow.open(map, marker.getPosition());
    });
    infoWindow.open(map, marker.getPosition());
    //构建自定义信息窗体
    function createInfoWindow(title, content) {
        var info = document.createElement("div");
        info.className = "info";

        //可以通过下面的方式修改自定义窗体的宽高
        //info.style.width = "400px";
        // 定义顶部标题
        var top = document.createElement("div");
        var titleD = document.createElement("div");
        var closeX = document.createElement("img");
        top.className = "info-top";
        titleD.innerHTML = title;
        closeX.src = "http://webapi.amap.com/images/close2.gif";
        closeX.onclick = closeInfoWindow;

        top.appendChild(titleD);
        top.appendChild(closeX);
        info.appendChild(top);

        // 定义中部内容
        var middle = document.createElement("div");
        middle.className = "info-middle";
        middle.style.backgroundColor = 'white';
        middle.innerHTML = content;
        info.appendChild(middle);

        // 定义底部内容
        var bottom = document.createElement("div");
        bottom.className = "info-bottom";
        bottom.style.position = 'relative';
        bottom.style.top = '0px';
        bottom.style.margin = '0 auto';
        var sharp = document.createElement("img");
        sharp.src = "http://webapi.amap.com/images/sharp.png";
        bottom.appendChild(sharp);
        info.appendChild(bottom);
        return info;
    }

    //关闭信息窗体
    function closeInfoWindow() {
        map.clearInfoWindow();
    }
}

//禁止点击
function disab(btn){
    btn.setAttribute("disabled", "disabled");
    $(btn).addClass("register_btn_hover");
}
//电话号码正则表达式
function isTelCode(str) {
    var reg=/^1(3|4|5|7|8)\d{9}$/;
    return reg.test(str);
};
//解析本地的邀请码
function myinviti(tipsed){
    var reg = new RegExp("(^|&)" + tipsed + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r) {
        var code = unescape(r[2]);
        return code;
    }
};
//生成二维码库函数
function xyqrcode(options,size) {
    var settings = {
        dom:'',
        render: 'canvas',   //生成二维码的格式还有image、div
        ecLevel:"H",
        text:"www.baidu.com",
        background:"#ffffff",
        fill:"#333333", //二维码纹路的颜色
        fontcolor:"#ff9818",
        fontname:"Ubuntu",
        image:{},
        label:"",
        mPosX:0.5,   //图片在X轴的位置
        mPosY:0.5,    //图片在X轴的位置
        mSize:0.27,   //图片大小
        minVersion:5,
        mode:0,
        quiet:1,
        radius:1,
        size:size
    };
    if (options) {
        $.extend(settings, options);//options对象跟settings比较，相同的就替换，没有的就添加

    }
    if(settings.dom.length==0){
        window.console.log("Error: dom empty!");
        return;
    }
    if(settings.url.length==0){
        window.console.log("Error: url empty!");
        return;
    }
    console.log(settings);
    settings.text=settings.url; //在qrcode生成二维码的地址是text。这里就把url赋值给text
    $(settings.dom).qrcode(settings);

}
